/*
 *
 *  * Copyright 2017 Zhongan.io All right reserved. This software is the
 *  * confidential and proprietary information of Zhongan.io ("Confidential
 *  * Information"). You shall not disclose such Confidential Information and shall
 *  * use it only in accordance with the terms of the license agreement you entered
 *  * into with Zhongan.io.
 *
 *
 */
package com.steed.rocketmq.producer.config.swagger;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * http://ip:port/swagger-ui.html
 * @author za-alvinzhou
 * Created in 19:39 2017/10/20
 */
@Configuration
@EnableConfigurationProperties(SwaggerProperties.class)
@EnableSwagger2
public class SwaggerConfig {

    /**
     * 注入属性
     */
    private final SwaggerProperties swaggerProperties;

    @Autowired
    public SwaggerConfig(SwaggerProperties swaggerProperties){
        this.swaggerProperties = swaggerProperties;
    }

    /**
     * 构造REST API 界面容器
     */
     @Bean
     public Docket createRestApi(){
         return  new  Docket(DocumentationType.SWAGGER_2)
                 .select()
                 //Api 生成扫描包路径
                 .apis(RequestHandlerSelectors.basePackage(swaggerProperties.getScanPackage()))
                 .build()
                 .apiInfo(apiInfo());
     }

    /**
     *  API界面信息
      * @return ApiInfo
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title(swaggerProperties.getTitle())
                .description(swaggerProperties.getDescription())
                .version(swaggerProperties.getVersion())
                .termsOfServiceUrl(swaggerProperties.getTermsOfServiceUrl())
                // 作者
                .contact(new Contact(swaggerProperties.getContactName(),"",swaggerProperties.getContactEmail()))
                .license(swaggerProperties.getLicense())
                .licenseUrl(swaggerProperties.getLicenseUrl())
                .build();
    }

}
